<?php
defined('BASEPATH') OR exit('No direct script access allowed');
?>
<!--返回错误信息-->
<?php echo validation_errors(); ?>
<!DOCTYPE html>
<html lang="en">

<head>
    <?php

    $title = [
        'title' => '',
    ];
    $this->load->view('/admin/common/header', $title);
    ?>
</head>

<body data-type="widgets">
<script src="/assets/js/theme.js"></script>
<div class="am-g tpl-g">

    <!--    头部   侧边菜单-->
    <?php $this->load->view('/admin/common/bodyLeft'); ?>
    <!-- 内容区域 -->
    <div class="tpl-content-wrapper">
        <div class="row-content am-cf">
            <div class="row">
                <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
                    <div class="widget am-cf">
                        <div class="widget-head am-cf">
                            <div class="widget-title  am-cf">
                                <ol class="am-breadcrumb am-breadcrumb-slash">
                                    <li><a href="/admin/check/index?page=1&type=1">审核管理</a></li>
                                    <li class="am-active">单据详情</li>
                                </ol>
                            </div>
                        </div>
                        <form method="post" enctype="multipart/form-data" class="am-form am-text-sm" id="submitForm">
                            <input type="hidden" name="id" value="<?php echo $list['id'] ?>">
                            <div class="widget-body  am-fr">
                                <div class="tpl-table-black-operation">
                                    <a href="javascript:void(0);" class="tpl-table-black-operation-del">
                                        基本信息
                                    </a>
                                </div>

                                <div style="margin-top: 20px">
                                    <div class="am-g">
                                        <!-- Row start -->
                                        <div class="am-u-sm-12">
                                            <div class="am-u-md-6">
                                                <!--                                                    <form class="am-form am-text-sm">-->
                                                <div class="am-form-group am-u-sm-12">
                                                    <label class="am-u-md-2 am-md-text-right am-padding-left-0 must"
                                                           for="code">单据编号</label>
                                                    <div class="am-u-md-10 ">
                                                        <?php
                                                        if(isset($list['needCode'])){
                                                            echo '<input type="text" name="code" value="'.$list['needCode'].'" id="code" readonly>';

                                                        }elseif (isset($list['code'])){

                                                            echo '<input type="text" name="code" value="'.$list['code'].'" id="code" readonly>';

                                                        }elseif(isset($list['purchaseCode'])){
                                                            echo '<input type="text" name="code" value="'.$list['purchaseCode'].'" id="code" readonly>';
                                                        }elseif(isset($list['stockOutCode'])){
                                                            echo '<input type="text" name="code" value="'.$list['stockOutCode'].'" id="code" readonly>';
                                                        }elseif(isset($list['stockPutCode'])){
                                                            echo '<input type="text" name="code" value="'.$list['stockPutCode'].'" id="code" readonly>';
                                                        }
                                                        ?>
                                                    </div>

                                                </div>

                                                <div class="am-form-group am-u-sm-12">
                                                    <label class="am-u-md-2 am-md-text-right am-padding-left-0 must"
                                                           for="source">所属项目</label>
                                                    <div class="am-u-md-10 ">
                                                        <?php
                                                        if($list['status'] !=0 ){
                                                            echo '<input  type="text" name="source" value='.$list['source'].' readonly>';
                                                        }else{
                                                            echo '<select class="form-control" name="source" id="source" data-am-selected="{btnWidth: \'100%\',maxHeight: 200}">';
                                                            foreach ($project as $v){
                                                                if($v['name'] == $list['source']) {
                                                                    echo '<option value="'.$v['name'].'" selected>'.$v['name'].'</option>';
                                                                }else{
                                                                    echo '<option value="'.$v['name'].'" >'.$v['name'].'</option>';
                                                                }
                                                            }
                                                            echo '</select>';
                                                        }
                                                        ?>
                                                    </div>


                                                </div>

                                                <div class="am-form-group am-u-sm-12">
                                                    <label class="am-u-md-2 am-md-text-right am-padding-left-0 must"
                                                           for="createTime">单据时间</label>
                                                    <div class="am-u-md-10">
                                                        <input type="text" class=" am-form-field" placeholder="选择单据时间" data-am-datepicker readonly  name="createTime" id="createTime" value="<?php echo date('Y-m-d',$list['createTime']) ?>" />
                                                    </div>
                                                </div>

                                                <div class="am-form-group am-u-sm-12">
                                                    <label class="am-u-md-2 am-md-text-right am-padding-left-0 must"
                                                           for="content">申请原因</label>
                                                    <div class="am-u-md-10 ">
                                                         <textarea  rows="5" name="content" id="content" readonly><?php echo trim($list['content'])?>
                                                         </textarea>
                                                    </div>

                                                </div>
                                            </div>

                                            <div class="am-u-md-6">
                                                <div class="am-form-group am-u-sm-12">
                                                    <label class="am-u-md-2 am-md-text-right am-padding-left-0 must"
                                                           for="name">单据名称</label>
                                                    <div class="am-u-md-10 ">
                                                        <input type="text"  name="name" value="<?php echo $list['name']?>"
                                                               id="name" readonly>
                                                    </div>


                                                </div>

                                                <div class="am-form-group am-u-sm-12">
                                                    <label class="am-u-md-2 am-md-text-right am-padding-left-0 must"
                                                           for="supplier">单据分类</label>
                                                    <div class="am-u-md-10 ">
                                                        <input type="text" value="<?php echo $list['type']?>" readonly/>

                                                    </div>
                                                </div>

                                                <div class="am-form-group am-u-sm-12">

                                                        <?php
                                                            if(isset($list['endTime'])){
                                                                echo '<label class="am-u-md-2 am-md-text-right am-padding-left-0" for="endTime">期望到货时间</label>
                                                    <div class="am-u-md-10"><input type="text" class="am-form-field" placeholder="选择期望到货时间" data-am-datepicker name="endTime" id="endTime" readonly value="'.date('Y-m-d',$list['endTime']).'"/>';
                                                            }
                                                        ?>
                                                    </div>
                                                </div>


                                            </div>
                                        </div>
                                        <!-- Row end -->
                                    </div>
                                    <hr>
                                </div>

                                <div class="tpl-table-black-operation">
                                    <a href="javascript:void(0);" class="tpl-table-black-operation-del">
                                        详细信息
                                    </a>
                                </div>

                                <!--   更换为goodsMessage 数据-->
                                <div style="margin-top: 20px">
                                    <div class="am-u-sm-12">
                                        <table width="100%"
                                               class="am-table am-table-compact am-table-striped tpl-table-black "
                                               id="example-r">
                                            <thead>
                                            <tr>
                                                <th style="width: 5%">序号</th>
                                                <th style="width: 15%">商品编码</th>
                                                <th style="width: 10%">商品名称</th>
                                                <th style="width: 15%">商品规格</th>
                                                <th style="width: 5%">单位</th>
                                                <?php
                                                    if($_GET['type'] == '普通需求单' || $_GET['type'] == '招投标项目需求单' || $_GET['type'] == '采购项目单'){
                                                        echo '<th style="width: 10%">进货数量</th>
                                                            <th style="width: 10%">进货单价(元)</th>
                                                            <th style="width: 10%">进货金额(元)</th>';
                                                    }else{
                                                        echo '<th style="width: 10%">换货数量</th>
                                                            <th style="width: 10%">换货单价(元)</th>
                                                            <th style="width: 10%">换货金额(元)</th>';
                                                    }

                                                ?>
                                                <th style="width: 20%">备注</th>
                                            </tr>
                                            </thead>
                                            <tbody  id="goodsMessage">
                                            <?php
                                            $list['goodsMessage'] = json_decode($list['goodsMessage'],true);

                                            foreach ($list['goodsMessage'] as $k=>$v){
                                                echo '<tr class="line">
                                              
                                                   <td class="order">'.$v['order'].'</td>
                                                <td data-id="'.$v['dataId'].'" class="product_no">'.$v['product_no'].'</td>
                                                <td class="name">'.$v['name'].'</td>
                                                <td class="specification"   >'.$v['specification'].'</td>
                                                <td class="goodsUnit">'.$v['goodsUnit'].'</td>';

                                                if($list['status'] != 0 || strstr($v['specification'], '商品规格+')){
                                                    echo '<td>
                                                    <div class="am-form">
                                                        <input type="text" name="" class="am-u-md-12 form-control quantity" value="'.$v['quantity'].'" readonly>
                                                    </div>
                                                </td>
                                                <td >
                                                    <div class="am-form">
                                                        <input type="text" name="" class="am-u-md-12 form-control price" value="'.$v['price'].'" readonly>
                                                    </div>
                                                </td>
                                                <td class="price-all">'.$v['priceAll'].'</td>
                                                <td>
                                                    <div class="am-form">
                                                        <input type="text" name="" class="am-u-md-12 form-control remarks" value="'.$v['remarks'].'" readonly>
                                                    </div>
                                                </td>
                                            </tr>';
                                                }else{
                                                    echo '          <td>
                                                    <div class="am-form">
                                                        <input type="text" name="" class="am-u-md-12 form-control quantity" value="'.$v['quantity'].'">
                                                    </div>
                                                </td>
                                                <td>
                                                    <div class="am-form">
                                                        <input type="text" name="" class="am-u-md-12 form-control price" value="'.$v['price'].'">
                                                    </div>
                                                </td>
                                                <td class="price-all">'.$v['priceAll'].'</td>

                                                <td>
                                                    <div class="am-form">
                                                        <input type="text" name="" class="am-u-md-12 form-control remarks" value="'.$v['remarks'].'">
                                                    </div>
                                                </td>
                                            </tr>';
                                                }

                                            }


                                            ?>

                                            <!-- more data -->
                                            </tbody>
                                        </table>
                                        <button type="button" class="am-btn am-btn-secondary"  data-am-modal="{target: '#changeCommodity', closeViaDimmer: 0, width: 900, height: 500}" id="chooseCommodity" disabled>选择商品</button>
                                        <div class="am-fr" style="font-size: 16px;line-height: 37px">
                                            共<span id="class"><?php $attribute = explode('/',$list['attribute']);echo $attribute[0].'</span>类,'.'<span id="quantity-all">'.$attribute[1].'</span>件商品';
                                                ?>

                                        </div>
                                        <hr>
                                    </div>
                                </div>

                                <div class="tpl-table-black-operation">
                                    <a href="javascript:void(0);" class="tpl-table-black-operation-del">
                                        审批信息
                                    </a>
                                </div>

                                <div style="margin-top: 20px">
                                    <div class="am-g">
                                        <!-- Row start -->
                                        <div class="am-u-sm-4">
                                        </div>
                                    </div>
                                </div>
                                <!-- Row end -->

                            </div>
                                <div class="am-u-sm-12">
                                    <?php
                                        if(isset($list['checkInfo'])){
                                            foreach ($list['checkInfo'] as $k2=>$v2){
                                                if($v2['status'] == 1){
                                                    $v2['status'] = '已同意';
                                                }else{
                                                    $v2['status'] = '已拒绝';
                                                }
                                                $v2['content'] = isset($v2['content']) && $v2['content'] ? $v2['content'] : '无评价';

                                                echo '<div class="am-u-md-6">
                                        <div class="am-form-group am-u-sm-12">
                                            <label class="am-u-md-2 am-md-text-right am-padding-left-0 must"
                                                   for="code">审批人</label>
                                            <div class="am-u-md-10 ">
                                                   <input type="text" name="code" value="'.$v2['checker'].'" id="code" readonly>
                                            </div>
                                        </div>
                                    </div>

                                    <div class="am-u-md-6">
                                        <div class="am-form-group am-u-sm-12">
                                            <label class="am-u-md-2 am-md-text-right am-padding-left-0 must"
                                                   for="name">审批状态</label>
                                            <div class="am-u-md-10 ">
                                                <input type="text"  name="name" value="'.$v2['status'].'" id="name" readonly>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="am-u-md-20">
                                        <div class="am-form-group am-u-sm-12">
                                            <label class="am-u-md-2 am-md-text-right am-padding-left-0 must"
                                                   for="name">审批信息</label>
                                            <div class="am-u-md-10 ">
                                                <textarea rows="4" cols="20" disabled="disabled">'.$v2['content'].'</textarea>
                                            </div>
                                        </div>
                                    </div>';
                                            }
                                        }else{
                                            echo '暂无审核信息';
                                        }

                                    ?>

                                </div>

                            <div class="am-u-sm-12 btn-box" style="margin: 20px 0">
<!--                                按钮的代码-->
                                <?php
                                    if(!$list['isCheck']){
                                        if(!__checkTrue($_GET['checkId']) || !__checkTrue($_GET['checkStatus']) || !__checkTrue($_GET['id'])){
                                            echo __alert('非法进入！');
                                        }
//                                        id=118&status=1&checkStatus=1&proId=30

                                        if(isset($_GET['status']) && $_GET['status'] == 1){
                                            echo '<input type="hidden" class="uri" value="/admin/check/edit?id='.$_GET['checkId'].'&checkStatus='.$_GET['checkStatus'].'&proId='.$_GET['id'].'&type='.$_GET['type'].'">';

                                            echo '<a href="javascript:;" data-am-modal="{target: \'#grade-box-success\', closeViaDimmer: 0, width: 400, height: 250}" class="click-success"><button type="button" class="am-btn am-btn-primary"><i class="am-icon-check"></i> 审核通过</button></a>
                                                <a href="javascript:;" data-am-modal="{target: \'#grade-box-ref\', closeViaDimmer: 0, width: 400, height: 250}" class="tpl-table-black-operation-del click-ref"> <button type="button" class="am-btn am-btn-danger"><i class="am-icon-close"></i> 审核拒绝</button> </a>
                                                    ';
                                        }else{
                                            echo '  <div class="tpl-table-black-operation">
                                                         <a href="javascript:void(0);" class="am-btn am-btn-default am-disabled">审核已拒绝 </a>
                                                </div>';
                                        }



                                    }
                                ?>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- 审核通过模态框 -->
<div class="am-modal am-modal-no-btn" tabindex="-1" id="grade-box-success">
    <div class="am-modal-dialog">
        <div class="am-modal-hd">通过理由
            <a href="javascript: void(0)" class="am-close am-close-spin" data-am-modal-close>&times;</a>
        </div>
        <div class="am-modal-bd">
            <form class="am-form am-form-horizontal">
                <div class="am-form-group">
                    <div class="am-u-sm-15">
                        <textarea rows="4" id="successContent" maxlength="128"></textarea>
                    </div>
                </div>
            </form>
            <div style="position: relative;top: 25px;">
                <button type="button" class="am-btn am-btn-primary am-u-sm-6" id="confirm-success" data-am-modal-close>确定</button>
                <button type="button" class="am-btn am-btn-danger am-u-sm-6" data-am-modal-close>取消</button>
            </div>
        </div>
    </div>
</div>

<!-- 审核拒绝模态框 -->
<div class="am-modal am-modal-no-btn" tabindex="-1" id="grade-box-ref">
    <div class="am-modal-dialog">
        <div class="am-modal-hd">拒绝理由
            <a href="javascript: void(0)" class="am-close am-close-spin" data-am-modal-close>&times;</a>
        </div>
        <div class="am-modal-bd">
            <form class="am-form am-form-horizontal">
                <div class="am-form-group">
                    <div class="am-u-sm-15">
                        <textarea rows="4" id="refContent" maxlength="128"></textarea>
                    </div>
                </div>
            </form>
            <div style="position: relative;top: 25px;">
                <button type="button" class="am-btn am-btn-primary am-u-sm-6" id="confirm-ref" data-am-modal-close>确定</button>
                <button type="button" class="am-btn am-btn-danger am-u-sm-6" data-am-modal-close>取消</button>
            </div>
        </div>
    </div>
</div>
<script>

    var successUrl = null;
    var refUrl = null;

    $(".click-success").on("click", function () {
        successUrl = $(this).siblings(".uri").val();
    });

    $(".click-ref").on("click", function () {
        refUrl = $(this).siblings(".uri").val();
    });


    // 点击确定提交审核通过
    $("#confirm-success").on("click",function(){
        var successContent = $("#successContent").val();
        window.location.href = successUrl+'&status=1&content='+successContent;
        console.log(successUrl+'&status=1&content='+successContent);
        console.log(successContent)
    });

    // 点击确定提交审核拒绝
    $("#confirm-ref").on("click",function(){

        var refContent = $("#refContent").val();
        window.location.href = refUrl+'&status=2&content='+refContent;
        console.log(refUrl+'&status=2&content='+refContent);
        console.log(refContent)
    });
</script>
<script src="/assets/js/amazeui.min.js"></script>
<script src="/assets/js/amazeui.datatables.min.js"></script>
<script src="/assets/js/dataTables.responsive.min.js"></script>
<script src="/assets/js/app.js"></script>
<script src="/assets/js/page.js"></script>
</body>

</html>